#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int min = 0;
    int max = 0;
    int num = 0;
    printf("请输入数据:>");
    scanf("%d%d", &min, &max);
    min = min <= 2 ? 2 : min;
    //堆区开辟空间
    char *STP = (char *) calloc(max - min, sizeof(char));
    if (STP == NULL) {
        perror("堆区开辟失败");
    }
    //素数的判别
    for (int i = min; i <= max; i++) {
        for (int j = 2; j <= sqrt(i); j++) {
            if (STP[j] == 0 && i % j == 0) {
                STP[i] = '1';
                break;
            }
        }
        if (STP[i] == 0) {
            num++;
            printf("%d ", i);
        }
    }
    printf("\n%d", num);
    //释放空间
    free(STP);
    STP = NULL;
    return 0;
}
